home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / src / WBBump_src.lha / WBBump_src / hmap2true.asm < prev    next >
Encoding:
Assembly Source File  |  1999-06-30  |  4.1 KB  |  238 lines

  1. *****************
  2. * hmap2true.asm *
  3. *****************
  4.  
  5.  
  6.  
  7. ***    WBBump - Bumpmapping on the Workbench!
  8.  
  9. ***    Copyright (C) 1999  Thomas Jensen - dm98411@edb.tietgen.dk
  10.  
  11. ***    This program is free software; you can redistribute it and/or modify
  12. ***    it under the terms of the GNU General Public License as published by
  13. ***    the Free Software Foundation; either version 2 of the License, or
  14. ***    (at your option) any later version.
  15.  
  16. ***    This program is distributed in the hope that it will be useful,
  17. ***    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ***    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ***    GNU General Public License for more details.
  20.  
  21. ***    You should have received a copy of the GNU General Public License
  22. ***    along with this program; if not, write to the Free Software Foundation,
  23. ***    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  
  25.  
  26.  
  27.  
  28.     MACHINE    68020
  29.  
  30.  
  31.     XDEF    hmap2true_iiiiiiiii
  32.  
  33.  
  34.  
  35. BOUNDS_UBYTE    MACRO        * \1 = reg
  36.  
  37.     cmp.w    #$ff,\1
  38.     bls    .j1\@
  39.     move.w    #$ff,\1
  40. .j1\@
  41.     ENDM
  42.  
  43.  
  44.  
  45.  
  46. GET_DIST    MACRO    * \1 = Dx    result reg (bits 0-15 will be cleared)
  47.             * \2 = Dx    temp reg (bits 8-15 must be 0)
  48.             * \3 = Dx    current pixel position
  49.             * \4 = Dx    current light position
  50.             * \5 = Ax    pointer to pixel 1 (eg. -1(a0))
  51.             * \6 = Ax    pointer to pixel 2 (eg. 1(a0))
  52.  
  53.     clr.w    \1
  54.     move.b    \6,\2        * pixel to the right
  55.     move.b    \5,\1        * pixel to the left
  56.     sub.w    \2,\1        * sub right pixel
  57.  
  58. *    asl.w    #2,\1        * make it look nicer
  59.  
  60.     add.w    \3,\1        * add current pixel position
  61.     sub.w    \4,\1        * sub light position
  62.  
  63.     * convert to positive value
  64.     bpl    .j1\@        * branch if plus
  65.     neg.w    \1        * else negate
  66. .j1\@
  67.  
  68.     ENDM
  69.  
  70.  
  71.  
  72.  
  73. ***    hmap2true( brighttable[256][256], hmap, inbuf:RGB, outbuf:RGB, skip, width, height, lightx, lighty )
  74.  
  75.  
  76. *** 36 brigthtable:    uchar ptr    - ptr to 256*256 table
  77. *** 32 hmap    :    char ptr    - ptr to heightmap
  78. *** 28 inbuf    :    RGB ptr        - ptr to src rgb buffer
  79. *** 24 outbuf    :    RGB ptr        - ptr to dest rgb buffer
  80. *** 20 skip    :    uchar        - value to add to in/out buf after each line
  81. *** 16 width    :    uword
  82. *** 12 height    :    uword
  83. ***  8 lightx    :    sword
  84. ***  4 lighty    :    sword
  85.  
  86.  
  87. hmap2true_iiiiiiiii:
  88.     * store value af A4 (E requirement)
  89.     move.l    a4,a4store
  90.     move.l    a5,a5store
  91.  
  92.     * get arguments from stack
  93.  
  94.     move.l    36(sp),.brighttable
  95.     move.l    .brighttable,a2
  96.  
  97.     move.l    32(sp),.hmap
  98.     move.l    .hmap,a0
  99.  
  100.     move.l    28(sp),.inbuf
  101.     move.l    .inbuf,a1
  102.  
  103.     move.l    24(sp),.outbuf
  104.     move.l    .outbuf,a5
  105.  
  106.     move.l    20(sp),.skip
  107.  
  108.     move.w    16+2(sp),.width
  109.     move.w    12+2(sp),.height
  110.  
  111.     move.w    8+2(sp),.lightx
  112.     move.w    4+2(sp),.lighty
  113.  
  114.     move.l    .hmap,a3
  115.     sub.l    16(sp),a3
  116.  
  117.     move.l    .hmap,a4
  118.     add.l    16(sp),a4
  119.  
  120.  
  121.  
  122.     clr.l    d2    * we need to use (Ax,D2.l)
  123.  
  124.     clr.l    d7
  125.  
  126.  
  127.     moveq.l    #0,d1    * d1 is y loop counter
  128. .ly
  129.     moveq.l    #0,d0    * d0 is x loop counter
  130. .lx
  131.  
  132.     * should we calc brightness ?
  133.     cmp.b    #05,(a0)
  134.     bls    .drawtrough
  135.  
  136.     * light x
  137.  
  138.     GET_DIST    d2, d7, d0, .lightx, -1(a0), 1(a0)
  139.  
  140.  
  141.     * light y
  142.  
  143.     GET_DIST    d3, d7, d1, .lighty, (a3), (a4)
  144.  
  145.  
  146.  
  147.     * bounds check
  148.  
  149.     BOUNDS_UBYTE    d2    * convert values > 255 to 255
  150.  
  151.     BOUNDS_UBYTE    d3    * convert values > 255 to 255
  152.  
  153.  
  154.     * prepare index word
  155.  
  156.     lsl.w    #8,d2        * x in upper 8 bits of index word
  157.     move.b    d3,d2        * and y in the lower
  158.  
  159.  
  160.     * get the actual brightness and put it into buffer
  161.  
  162.     move.b    0(a2,d2.l),d7    * brightness in d7
  163.  
  164.     not.b    d7        * the brightness is actually darkness in the table (might change that)
  165.  
  166.  
  167.     MACRO    DO_COLOR
  168.  
  169.     clr.w    d4
  170.  
  171.     move.b    (a1)+,d4    * get color value
  172.     add.w    d7,d4        * add brightness
  173.     BOUNDS_UBYTE d4        * overflow ?
  174.  
  175.     move.b    d4,(a5)+
  176.     ENDM
  177.  
  178.  
  179.     REPT 3
  180.     DO_COLOR    * red, green and blue
  181.     ENDR
  182.  
  183.     bra    .loopout    * skip the drawtrough
  184.  
  185.  
  186. .drawtrough    * just copy
  187.  
  188.     REPT 3
  189.     move.b    (a1)+,(a5)+
  190.     ENDR
  191.  
  192. .loopout
  193.  
  194.     * increase pointers
  195.     addq    #1,a0
  196.     addq    #1,a3
  197.     addq    #1,a4
  198.  
  199.  
  200.  
  201.     *** x loop ***
  202.     addq.w    #1,d0
  203.     cmp.w    .width,d0
  204.     bne    .lx
  205.  
  206.     * add skip values
  207.     REPT 3
  208.     add.l    .skip,a1
  209.     add.l    .skip,a5
  210.     ENDR
  211.  
  212.     *** y loop ***
  213.     addq.w    #1,d1
  214.     cmp.w    .height,d1
  215.     bne    .ly
  216.  
  217.     * put original a4 value back where it belongs
  218.     move.l    a4store,a4
  219.     move.l    a5store,a5
  220.  
  221.     rts
  222.  
  223.  
  224. *** local variables
  225.  
  226. .brighttable    dc.l    0
  227. .hmap        dc.l    0
  228. .inbuf        dc.l    0
  229. .outbuf        dc.l    0
  230. .skip        dc.l    0
  231. .width        dc.w    0
  232. .height        dc.w    0
  233. .lightx        dc.w    0
  234. .lighty        dc.w    0
  235.  
  236. a4store:    dc.l    0
  237. a5store:    dc.l    0
  238.